﻿$(function () {
    EquipmentFind()
});

//仓库详情
function EquipmentFind() {
    layui.use('layer', function () {
        var form = layui.form;

        var equipmentId = localStorage["equipmentId"]
        // 创建表格实例
        $.ajax({
            url: "/Equipment/EquipmentsFind",
            type: "get",
            data: {
                equipmentId: equipmentId,
            },
            success: function (data) {
                data = JSON.parse(data);
                console.log(data.data);
                // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                $(data.data).each(function () {

                    $('#equipmentId').text(this.equipmentId)
                    $('#equipmentName').text(this.equipmentName)
                    $('#equipmentNumbering').text(this.equipmentNumbering)

                    switch (this.equipmentType) {
                        case 1:
                            $('#equipmentType').text('类型一');
                            break;
                        case 2:
                            $('#equipmentType').text('类型二');
                            break;
                        case 3:
                            $('#equipmentType').text('类型三');
                            break;
                        default:
                    }

                    $('#equipmentProductionLine').text(this.equipmentProductionLine);
                    $("#equipmentState").text(this.equipmentState == 1 ? "正常" : "异常")
                    $('#equipmentAddPeople').text(this.equipmentAddPeople)

                    var formattedAddTime1 = formatTime(this.equipmentProcurementData);
                    $('#equipmentProcurementData').text(formattedAddTime1);

                    var formattedAddTime2 = formatTime(this.equipmentAddData);
                    $('#equipmentAddData').text(formattedAddTime2);

                    $('#equipmentImage').text(this.equipmentImage)
                    $('#addName').text(this.addName)

                    var formattedAddTime = formatTime(this.addTime);
                    $('#addTime').text(formattedAddTime);
                    //$('#addTime').text(this.addTime) 

                    form.render();
                })
            }
        });
    })

    //本仓库的库区显示
    //ParticularsShowReservoir()
    ////本仓库的库区的全部库位显示
    //ParticularsShowSupplier()
}

function formatTime(timeStamp) {
    if (timeStamp) {
        var date = new Date(timeStamp);
        var year = date.getFullYear();
        var month = ('0' + (date.getMonth() + 1)).slice(-2);
        var day = ('0' + date.getDate()).slice(-2);
        var hour = ('0' + date.getHours()).slice(-2);
        var minute = ('0' + date.getMinutes()).slice(-2);
        var second = ('0' + date.getSeconds()).slice(-2);
        return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
    }
    return "";
}

